package com.ruoyi.project.digital.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.project.digital.domain.enums.YesOrNoStatus;
import com.ruoyi.project.digital.domain.vo.NoticeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.digital.mapper.NoticeMapper;
import com.ruoyi.project.digital.domain.Notice;
import com.ruoyi.project.digital.service.INoticeService;

/**
 * 系统消息  Service业务层处理
 *
 * @author ruoyi
 * @date 2023-10-31
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService
{

    /**
     * 查询系统消息
     *
     * @param id 系统消息  ID
     * @return 系统消息
     */
    @Override
    public Notice selectNoticeById(Long id)
    {
        return baseMapper.selectNoticeById(id);
    }

    /**
     * 查询系统消息  列表
     *
     * @param notice 系统消息
     * @return 系统消息
     */
    @Override
    public List<Notice> selectNoticeList(Notice notice)
    {
        return baseMapper.selectNoticeList(notice);
    }

    /**
     * 新增系统消息
     *
     * @param notice 系统消息
     * @return 结果
     */
    @Override
    public int insertNotice(Notice notice)
    {
        notice.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insertNotice(notice);
    }

    /**
     * 修改系统消息
     *
     * @param notice 系统消息
     * @return 结果
     */
    @Override
    public int updateNotice(Notice notice)
    {
        return baseMapper.updateNotice(notice);
    }

    /**
     * 批量删除系统消息
     *
     * @param ids 需要删除的系统消息  ID
     * @return 结果
     */
    @Override
    public int deleteNoticeByIds(Long[] ids)
    {
        return baseMapper.deleteNoticeByIds(ids);
    }

    /**
     * 删除系统消息  信息
     *
     * @param id 系统消息  ID
     * @return 结果
     */
    @Override
    public int deleteNoticeById(Long id)
    {
        return baseMapper.deleteNoticeById(id);
    }

    @Override
    public Integer noReadNumber(Long id) {
        QueryWrapper<Notice> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",id);
        queryWrapper.eq("is_read", YesOrNoStatus.YES.getValue());
        Integer count=baseMapper.selectCount(queryWrapper);
        return count;
    }

    @Override
    public List<NoticeVo> noReadList(Long id) {
         List<NoticeVo> voList=baseMapper.readList(id,YesOrNoStatus.NO.getValue());
        return voList;
    }

    @Override
    public List<NoticeVo> readList(Long id) {
        List<NoticeVo> voList=baseMapper.readList(id,YesOrNoStatus.YES.getValue());
        return voList;
    }
}
